//父类 通用方法
const maps = require('../common/errmap/errmap');
module.exports = class extends think.Controller {

    constructor(ctx) {
        super(ctx);
        this.maps = new maps();
    }

    resInsert(res) {
        if (res >= 0) {
            return this.resSuccess();
        }
        else {
            return this.resErrno(1100)
        }
    }

    resDelete(res) {
        if (res > 0)
            return this.resSuccess();
        else return this.resErrno(1101)
    }

    resUpdate(res) {
        if (res > 0)
            return this.resSuccess();
        else return this.resErrno(1102)
    }

    resSelect(res) {
        if (think.isEmpty(res)) return this.resEmpty();
        return this.resSuccessWithData(res);
    }

    // ok
    resErrmsg(errmsg) {
        return this.fail(this.maps.mapErrmsg(errmsg));
    }

    // ok
    resErrno(errno) {
        return this.fail(this.maps.mapErrno(errno));
    }

    //成功 ok
    resSuccess() {
        return this.resErrno(0);
    }

    resSuccessWithData(data){
        if(think.isEmpty(data) && data!==0){
            return this.resEmpty();
        }
        return this.fail(this.maps.mapErrno(0,data));
    }

    //空 ok
    resEmpty() {
        return this.fail(this.maps.mapErrno(1000));
    }

    //0k
    resSyserr() {
        return this.fail(this.maps.mapErrno(-1));
    }

    //没找到
    resNotFind() {
        return this.resErrno(9900);
    }
};